/*
               File: AgrReg
        Description: Agregar Registro
             Author: GeneXus Java Generator version 8_0_9-040
       Generated on: 28 de Setiembre de 2010 16:0:53.33
       Program type: Callable routine
          Main DBMS: sqlserver
*/
import java.sql.*;
import com.genexus.db.*;
import com.genexus.*;
import com.genexus.distributed.*;

public final class pagrreg extends GXProcedure
{
   public pagrreg( int remoteHandle )
   {
      super( remoteHandle , new ModelContext( pagrreg.class ), "" );
   }

   public pagrreg( int remoteHandle ,
                   ModelContext context )
   {
      super( remoteHandle , context, "" );
   }

   public void execute( String aP0 ,
                        String aP1 ,
                        String aP2 ,
                        String aP3 ,
                        String aP4 ,
                        byte[] aP5 )
   {
      execute_int(aP0, aP1, aP2, aP3, aP4, aP5);
   }

   private void execute_int( String aP0 ,
                             String aP1 ,
                             String aP2 ,
                             String aP3 ,
                             String aP4 ,
                             byte[] aP5 )
   {
      pagrreg.this.AV14Codaux = aP0;
      pagrreg.this.AV11Descri = aP1;
      pagrreg.this.AV15Tipo = aP2;
      pagrreg.this.AV13Usuari = aP3;
      pagrreg.this.AV10Tabla = aP4;
      pagrreg.this.aP5 = aP5;
      initialize();
      /* GeneXus formulas */
      /* Output device settings */
      if ( ( GXutil.strcmp(AV10Tabla, "MMCMB10") == 0 ) )
      {
         AV9Pout = 0 ;
         AV8Codigo = 0 ;
         /* Using cursor P00122 */
         pr_default.execute(0);
         while ( (pr_default.getStatus(0) != 101) )
         {
            A523CmbCod = P00122_A523CmbCod[0] ;
            AV8Codigo = A523CmbCod ;
            /* Exit For each command. Update data (if necessary), close cursors & exit. */
            if (true) break;
            /* Check if program is canceled. */
            pr_default.readNext(0);
         }
         pr_default.close(0);
         AV8Codigo = (int)(AV8Codigo+1) ;
         /*
            INSERT RECORD ON TABLE MMCMB10

         */
         A523CmbCod = AV8Codigo ;
         A578CmbNom = GXutil.upper( GXutil.trim( AV11Descri)) ;
         A579CmbEst = "1" ;
         A582CmbUCR = AV13Usuari ;
         A580CmbFCR = GXutil.serverDate( context, remoteHandle, "DEFAULT") ;
         A581CmbHCR = GXutil.serverTime( context, remoteHandle, "DEFAULT") ;
         AV9Pout = (byte)(1) ;
         /* Using cursor P00123 */
         pr_default.execute(1, new Object[] {new Integer(A523CmbCod), A578CmbNom, A579CmbEst, A580CmbFCR, A581CmbHCR, A582CmbUCR});
         if ( (pr_default.getStatus(1) == 1) )
         {
            Gx_err = (short)(1) ;
            Gx_emsg = localUtil.getMessages().getMessage("noupdate") ;
         }
         else
         {
            Gx_err = 0 ;
            Gx_emsg = "" ;
         }
         /* End Insert */
      }
      else if ( ( GXutil.strcmp(AV10Tabla, "MMTAU10") == 0 ) )
      {
         AV9Pout = 0 ;
         AV8Codigo = 0 ;
         /* Using cursor P00124 */
         pr_default.execute(2);
         while ( (pr_default.getStatus(2) != 101) )
         {
            A376TipAut = P00124_A376TipAut[0] ;
            AV8Codigo = A376TipAut ;
            /* Exit For each command. Update data (if necessary), close cursors & exit. */
            if (true) break;
            /* Check if program is canceled. */
            pr_default.readNext(2);
         }
         pr_default.close(2);
         AV8Codigo = (int)(AV8Codigo+1) ;
         /*
            INSERT RECORD ON TABLE MMTAU10

         */
         A376TipAut = (byte)(AV8Codigo) ;
         A377TipAut = GXutil.upper( GXutil.trim( AV11Descri)) ;
         A378TipAut = "1" ;
         A381TipAut = AV13Usuari ;
         A379TipAut = GXutil.serverDate( context, remoteHandle, "DEFAULT") ;
         A380TipAut = GXutil.serverTime( context, remoteHandle, "DEFAULT") ;
         AV9Pout = (byte)(1) ;
         /* Using cursor P00125 */
         pr_default.execute(3, new Object[] {new Byte(A376TipAut), A377TipAut, A378TipAut, A379TipAut, A380TipAut, A381TipAut});
         if ( (pr_default.getStatus(3) == 1) )
         {
            Gx_err = (short)(1) ;
            Gx_emsg = localUtil.getMessages().getMessage("noupdate") ;
         }
         else
         {
            Gx_err = 0 ;
            Gx_emsg = "" ;
         }
         /* End Insert */
      }
      else if ( ( GXutil.strcmp(AV10Tabla, "MMMRC10") == 0 ) )
      {
         AV9Pout = 0 ;
         /*
            INSERT RECORD ON TABLE MMMRC10

         */
         A189MarCod = AV14Codaux ;
         A357MarNom = GXutil.upper( GXutil.trim( AV11Descri)) ;
         A358MarTip = AV15Tipo ;
         A190MarEst = "1" ;
         A361MarUCR = AV13Usuari ;
         A359MarFCR = GXutil.serverDate( context, remoteHandle, "DEFAULT") ;
         A360MarHCR = GXutil.serverTime( context, remoteHandle, "DEFAULT") ;
         AV9Pout = (byte)(1) ;
         /* Using cursor P00126 */
         pr_default.execute(4, new Object[] {A189MarCod, A357MarNom, A358MarTip, A190MarEst, A359MarFCR, A360MarHCR, A361MarUCR});
         if ( (pr_default.getStatus(4) == 1) )
         {
            Gx_err = (short)(1) ;
            Gx_emsg = localUtil.getMessages().getMessage("noupdate") ;
         }
         else
         {
            Gx_err = 0 ;
            Gx_emsg = "" ;
         }
         /* End Insert */
      }
      cleanup();
   }

   protected void cleanup( )
   {
      this.aP5[0] = pagrreg.this.AV9Pout;
      exitApplication();
   }

   /* Aggregate/select formulas */
   public void initialize( )
   {
      AV9Pout = 0 ;
      AV8Codigo = 0 ;
      P00122_A523CmbCod = new int[1] ;
      A523CmbCod = 0 ;
      GX_INS51 = 0 ;
      A578CmbNom = "" ;
      A579CmbEst = "" ;
      A582CmbUCR = "" ;
      A580CmbFCR = GXutil.nullDate() ;
      A581CmbHCR = "" ;
      Gx_err = 0 ;
      Gx_emsg = "" ;
      P00124_A376TipAut = new byte[1] ;
      A376TipAut = 0 ;
      GX_INS27 = 0 ;
      A377TipAut = "" ;
      A378TipAut = "" ;
      A381TipAut = "" ;
      A379TipAut = GXutil.nullDate() ;
      A380TipAut = "" ;
      GX_INS25 = 0 ;
      A189MarCod = "" ;
      A357MarNom = "" ;
      A358MarTip = "" ;
      A190MarEst = "" ;
      A361MarUCR = "" ;
      A359MarFCR = GXutil.nullDate() ;
      A360MarHCR = "" ;
      pr_default = new DataStoreProvider(context, remoteHandle, new pagrreg__default(),
         new Object[] {
             new Object[] {
            P00122_A523CmbCod
            }
            , new Object[] {
            }
            , new Object[] {
            P00124_A376TipAut
            }
            , new Object[] {
            }
            , new Object[] {
            }
         }
      );
      /* GeneXus formulas. */
      Gx_err = 0 ;
   }

   private byte AV9Pout ;
   private byte A376TipAut ;
   private short Gx_err ;
   private int AV8Codigo ;
   private int A523CmbCod ;
   private int GX_INS51 ;
   private int GX_INS27 ;
   private int GX_INS25 ;
   private String AV14Codaux ;
   private String AV11Descri ;
   private String AV15Tipo ;
   private String AV13Usuari ;
   private String AV10Tabla ;
   private String A578CmbNom ;
   private String A579CmbEst ;
   private String A582CmbUCR ;
   private String A581CmbHCR ;
   private String Gx_emsg ;
   private String A377TipAut ;
   private String A378TipAut ;
   private String A381TipAut ;
   private String A380TipAut ;
   private String A189MarCod ;
   private String A357MarNom ;
   private String A358MarTip ;
   private String A190MarEst ;
   private String A361MarUCR ;
   private String A360MarHCR ;
   private java.util.Date A580CmbFCR ;
   private java.util.Date A379TipAut ;
   private java.util.Date A359MarFCR ;
   private byte[] aP5 ;
   private IDataStoreProvider pr_default ;
   private int[] P00122_A523CmbCod ;
   private byte[] P00124_A376TipAut ;
}

final class pagrreg__default extends DataStoreHelperBase implements ILocalDataStoreHelper
{
   public Cursor[] getCursors( )
   {
      return new Cursor[] {
          new ForEachCursor("P00122", "SELECT [CmbCod] FROM [MMCMB10] WITH (NOLOCK) ORDER BY [CmbCod] DESC ",false, GX_NOMASK + GX_MASKLOOPLOCK, false, this,0,false )
         ,new UpdateCursor("P00123", "INSERT INTO [MMCMB10] ([CmbCod], [CmbNom], [CmbEst], [CmbFCR], [CmbHCR], [CmbUCR], [CmbFUM], [CmbHUM], [CmbUUM]) VALUES (?, ?, ?, ?, ?, ?, convert( DATETIME, '17530101', 112 ), ' ', ' ')", GX_NOMASK + GX_MASKLOOPLOCK)
         ,new ForEachCursor("P00124", "SELECT [TipAutCod] FROM [MMTAU10] WITH (NOLOCK) ORDER BY [TipAutCod] DESC ",false, GX_NOMASK + GX_MASKLOOPLOCK, false, this,0,false )
         ,new UpdateCursor("P00125", "INSERT INTO [MMTAU10] ([TipAutCod], [TipAutNom], [TipAutEst], [TipAutFCR], [TipAutHCR], [TipAutUCR], [TipAutFUM], [TipAutHUM], [TipAutUUM]) VALUES (?, ?, ?, ?, ?, ?, convert( DATETIME, '17530101', 112 ), ' ', ' ')", GX_NOMASK + GX_MASKLOOPLOCK)
         ,new UpdateCursor("P00126", "INSERT INTO [MMMRC10] ([MarCod], [MarNom], [MarTip], [MarEst], [MarFCR], [MarHCR], [MarUCR], [MarFUM], [MarHUM], [MarUUM]) VALUES (?, ?, ?, ?, ?, ?, ?, convert( DATETIME, '17530101', 112 ), ' ', ' ')", GX_NOMASK + GX_MASKLOOPLOCK)
      };
   }

   public void getResults( int cursor ,
                           IFieldGetter rslt ,
                           Object[] buf ) throws SQLException
   {
      switch ( cursor )
      {
            case 0 :
               ((int[]) buf[0])[0] = rslt.getInt(1) ;
               break;
            case 2 :
               ((byte[]) buf[0])[0] = rslt.getByte(1) ;
               break;
      }
   }

   public void setParameters( int cursor ,
                              IFieldSetter stmt ,
                              Object[] parms ) throws SQLException
   {
      switch ( cursor )
      {
            case 1 :
               stmt.setInt(1, ((Integer) parms[0]).intValue());
               stmt.setString(2, (String)parms[1], 50);
               stmt.setString(3, (String)parms[2], 1);
               stmt.setDate(4, (java.util.Date)parms[3]);
               stmt.setString(5, (String)parms[4], 8);
               stmt.setString(6, (String)parms[5], 10);
               break;
            case 3 :
               stmt.setByte(1, ((Byte) parms[0]).byteValue());
               stmt.setString(2, (String)parms[1], 20);
               stmt.setString(3, (String)parms[2], 1);
               stmt.setDate(4, (java.util.Date)parms[3]);
               stmt.setString(5, (String)parms[4], 8);
               stmt.setString(6, (String)parms[5], 10);
               break;
            case 4 :
               stmt.setString(1, (String)parms[0], 10);
               stmt.setString(2, (String)parms[1], 20);
               stmt.setString(3, (String)parms[2], 1);
               stmt.setString(4, (String)parms[3], 1);
               stmt.setDate(5, (java.util.Date)parms[4]);
               stmt.setString(6, (String)parms[5], 8);
               stmt.setString(7, (String)parms[6], 10);
               break;
      }
   }

}

